package com.firebird.app.fekpsl.adapter.classroom

import android.content.Context
import android.view.View
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.firebird.app.fekpsl.R
import com.firebird.app.fekpsl.bean.Paper
import com.firebird.app.fekpsl.bean.Wall
import com.firebird.app.fekpsl.utils.TimeFriendlyUtil.friendlyTime
/**
 * Created by firebird on 2018/4/22.
 */
class QuestionPracticeAdapter(private val context: Context?, datas: MutableList<Paper>)
    : BaseQuickAdapter<Paper, BaseViewHolder>(R.layout.item_question_practice_list,datas) {
    override fun convert(holder: BaseViewHolder?, item: Paper?) {
        item ?: return
        holder ?: return
        val index=holder.layoutPosition

        val authorStr = if (item.is_explicit==1) item.nice_name else item.real_name
        holder.setText(R.id.tv_paper_title, item.name)
                .setText(R.id.tv_paper_author, authorStr)
                .setText(R.id.tv_paper_date,item.create_time)
                .setImageResource(R.id.iv_like,
                        if(item.collect>0) R.drawable.ic_like else R.drawable.ic_like_not
                )
                .addOnClickListener(R.id.iv_like)
        val paperDesc="答题时间:"+item.suggest_time+"题目总数:"+item.question_count;
        holder.setText(R.id.tv_paper_desc, paperDesc)
        val friendlyTime=friendlyTime(item.create_time)
        holder.setText(R.id.tv_paper_date, friendlyTime)

        val tv_top = holder.getView<TextView>(R.id.tv_paper_top)
        if (item.top > 0) {
            tv_top.visibility = View.VISIBLE
        } else {
            tv_top.visibility = View.GONE
        }
        holder.setText(R.id.tv_paper_first_category_name, item.first_category)
        holder.setText(R.id.tv_paper_second_category_name, item.second_category)
    }
}
